package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.commen.CustomException;
import com.itheima.reggie.commen.R;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.mapper.CategoryMapper;
import com.itheima.reggie.service.ICategoryService;
import com.itheima.reggie.service.IDishService;
import com.itheima.reggie.service.ISetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements ICategoryService {
    @Autowired
    private IDishService dishService;
    @Autowired
    private ISetmealService setmealService;
    @Override
    public void remove(Long id) {
        QueryWrapper qw = new QueryWrapper();
        qw.eq("category_id",id);
        int dishCount = dishService.count(qw);
        int setmealCount = setmealService.count(qw);
        if (dishCount > 0) {
            throw  new CustomException("当前分类下有菜品，不能删除");
        }
        if (setmealCount > 0) {
            throw  new CustomException("当前分类下有套餐，不能删除");
        }
    }
}
